(() => {

    'use strict';
    goog.provide('Blockly.Blocks.ruilong');
    goog.require('Blockly.Blocks');
    goog.require('path');

    const mediaDirPath = path.join(document.currentScript.src, '../../media/');

    Blockly.Msg['RUILONG_HUE'] = 120;



Blockly.Blocks.ruilong_emitter = {
  init: function() {
    this.setColour(Blockly.Msg['RUILONG_HUE']);
    this.appendDummyInput("").appendField("读取2.4G发射手柄");
    this.appendDummyInput("").appendField(new Blockly.FieldDropdown([["A", "0"],["B", "2"],["C", "1"],["D", "3"], 
      ["E(↑)", "4"],["F(←)", "6"],["G(↓)", "5"],["H(→)", "7"]]), 'CH')
    this.setOutput(true, Boolean);
    this.setInputsInline(true);
    this.setTooltip('');
  }
};

    //初始化RFID
Blockly.Blocks.ruilong_I2C_MFRC522_init = {
  init: function () {
    this.appendDummyInput()
    .appendField(Blockly.Msg.MIXLY_SETUP + "I2C RFID")
    .appendField(new Blockly.FieldTextInput("rfid"), "rfid_name");

            this.setInputsInline(true);
            this.setPreviousStatement(true, null);
            this.setNextStatement(true, null);
            this.setColour(Blockly.Msg['RUILONG_HUE']);
            this.setTooltip("");
            this.setHelpUrl("");
          }
        };

//RFID侦测到信号
Blockly.Blocks.ruilong_I2C_MFRC522_IsNewCard = {
  init: function () {
    this.appendDummyInput()
    .appendField("I2C RFID")
    .appendField(new Blockly.FieldTextInput("rfid"), "rfid_name")
    .appendField(" " + Blockly.Msg.MIXLY_COMMUNICATION_RFID_ON_DETECTED);
    this.appendStatementInput("DO")
    .setCheck(null);
    this.setInputsInline(false);
    this.setPreviousStatement(true, null);
    this.setNextStatement(true, null);
    this.setColour(Blockly.Msg['RUILONG_HUE']);
    this.setTooltip("");
    this.setHelpUrl("");
  }
};

//RFID读取卡号
Blockly.Blocks.ruilong_I2C_MFRC522_ReadCardUID = {
  init: function () {
    this.appendDummyInput()
    .appendField("I2C RFID")
    .appendField(new Blockly.FieldTextInput("rfid"), "rfid_name")
    .appendField(" " + Blockly.Msg.MIXLY_RFID_READ_CARD_UID);
    this.setInputsInline(false);
    this.setOutput(true, null);
    this.setColour(Blockly.Msg['RUILONG_HUE']);
    this.setTooltip("");
    this.setHelpUrl("");
  }
};

//RFID写卡
Blockly.Blocks.ruilong_I2C_MFRC522_WriteCard = {
  init: function () {
    this.appendDummyInput()
    .appendField("I2C RFID")
    .appendField(new Blockly.FieldTextInput("rfid"), "rfid_name")
    .appendField(" " + Blockly.Msg.MIXLY_RFID_WRITE_CARD);
    this.appendValueInput("block")
    .setCheck(null)
    .setAlign(Blockly.ALIGN_RIGHT)
    .appendField(Blockly.Msg.MIXLY_COMMUNICATION_DATA_BLOCK);
    this.appendValueInput("buffer")
    .setCheck(null)
    .setAlign(Blockly.ALIGN_RIGHT)
    .appendField(Blockly.Msg.MIXLY_RFID_BYTE_ARRAY);
    this.appendValueInput("length")
    .setCheck(null)
    .setAlign(Blockly.ALIGN_RIGHT)
    .appendField(Blockly.Msg.MIXLY_I2C_SLAVE_WRITE_ARRAY_ARRAYLENGTH);
    this.setInputsInline(true);
    this.setPreviousStatement(true, null);
    this.setNextStatement(true, null);
    this.setColour(Blockly.Msg['RUILONG_HUE']);
    this.setTooltip("");
    this.setHelpUrl("");
  }
};

//RFID读卡
Blockly.Blocks.ruilong_I2C_MFRC522_ReadCard = {
  init: function () {
    this.appendDummyInput()
    .appendField("I2C RFID")
    .appendField(new Blockly.FieldTextInput("rfid"), "rfid_name")
    .appendField(" " + Blockly.Msg.MIXLY_RFID_READ_CARD);
    this.appendValueInput("block")
    .setCheck(null)
    .setAlign(Blockly.ALIGN_RIGHT)
    .appendField(Blockly.Msg.MIXLY_COMMUNICATION_DATA_BLOCK);
    this.appendValueInput("buffer")
    .setCheck(null)
    .setAlign(Blockly.ALIGN_RIGHT)
    .appendField(Blockly.Msg.SAVETO + " " + Blockly.Msg.MIXLY_RFID_BYTE_ARRAY);
    this.appendValueInput("length")
    .setCheck(null)
    .setAlign(Blockly.ALIGN_RIGHT)
    .appendField(Blockly.Msg.MIXLY_I2C_SLAVE_WRITE_ARRAY_ARRAYLENGTH);
    this.setInputsInline(true);
    this.setPreviousStatement(true, null);
    this.setNextStatement(true, null);
    this.setColour(Blockly.Msg['RUILONG_HUE']);
    this.setTooltip("");
    this.setHelpUrl("");
  }
};

  })();